@var isNew = serialNumber.ID! == null;
@var overSeriLenMsg = lisFun.escapeForQuot('{0}超过流水号长度限制！','{0}');
<style>
.n-invalid.show-validate-mark{border:1px solid #f00;}
</style>
<script type="text/javascript">
function doSave(){
    var $form = $("#serialNumberForm");
    $form.validator("holdSubmit",true);
    $.ajax({
        url:"${basePath}/sys/serialnumber/save",
        type:"post",
        data:$form.serialize(),
        dataType:"json",
        success:function(result,status,xhr){
            clearTipMsgs("wait-msg");
            if(result.code == 0){
                MessageBox.success(result.message);
                _tabs.showPage("list");
            }else if(result.code > 0){
                appendTipMessage("error-msg",result.message);
            }
            $form.validator("holdSubmit",false);
        },
        error:function(xhr,status,err){
            console.warn("ajax response error: {status:'" + status + "',exception:'" + err + "'}");
            clearTipMsgs("wait-msg");
            appendTipMessage("error-msg","服务器错误，请稍后再试！");
            $form.validator("holdSubmit",false);
        }
    });
}
function initVld(){
    var $form = $("#serialNumberForm");
    $form.validator("destroy").validator({
        focusInvalid:false, //校验失败不自动获得焦点
        focusCleanup:true, //获得焦点时自动清除消息
        msgMaker:false, //不要自动生成消息
        timely:false, //关闭即时校验
        rules:{
            codeFormat:[/^[_0-9a-zA-Z]*$/,"{0}仅允许字母、数字、下划线！"],
            overSeriLen:function(el,param,field){
                var seriNumLenVal = $("#seriNumLen").val();
                var curVal = $(el).val();
                if(!isEmpty(seriNumLenVal) && !isEmpty(curVal)){
                    var seriLen = Number(seriNumLenVal);
                    var curValNum = Number(curVal);
                    if(String(curValNum).length > seriLen){
                        return "${overSeriLenMsg}";
                    }
                }
            }
        },
        fields:{
            "serialNumber.RULE_CODE":{rule:"required;codeFormat;remote[${basePath}/sys/serialnumber/checkRuleCode, serialNumber.ID];"},
            "serialNumber.RULE_NAME":{rule:"required;remote[${basePath}/sys/serialnumber/checkRuleName, serialNumber.ID];"},
            "serialNumber.RULE_TYPE":{rule:"required;"},
            "serialNumber.SERIAL_LENGTH":{rule:"required;"},
            "serialNumber.CURRENT_VALUE":{rule:"required;overSeriLen;"},
            "serialNumber.INIT_VALUE":{rule:"required;overSeriLen;match[lte, serialNumber.CURRENT_VALUE];"},
            "serialNumber.STEP":{rule:"overSeriLen;"}
        },
        display:function(element){
            if(element.type == "radio"){
                return $form.find("label[for='" + element.name + "']").text();
            }else{
                return $form.find("label[for='" + element.id + "']").text();
            }
        },
        valid:function(form){
            doSave();
        },
        invalid:function(form,errors){
            clearTipMsgs("wait-msg");
            appendTipMsgRows("error-msg",errors);
            $form.find(".n-invalid").addClass("show-validate-mark");
        }
    })
}
function save(){
    var $form = $("#serialNumberForm");
    clearTipMsgs(["wait-msg","alert-msg","error-msg"]);
    $form.find(".show-validate-mark").removeClass("show-validate-mark");
    appendTipMessage("wait-msg","校验保存中...");
    initVld();
    $form.trigger("validate");
}
</script>
<div class="form-container">
    <div class="box">
        <div class="row visa-row">
            <div id="wait-msg" class="alert alert-info" style="background:url(${baseStaticUrl}/images/ajax-loader.gif) no-repeat scroll 15px 50%;padding-left:35px;display:none;"></div>
            <div id="alert-msg" class="alert alert-success" style="display:none;"></div>
            <div id="error-msg" class="alert alert-danger" style="display:none;"></div>
        </div>
        <div class="row visa-row">
            <h6 class="mg-b-20 h6-mar-sm">
                <strong>规则信息</strong>
            </h6>
            <form id="serialNumberForm" class="form_input" method="post">
                <div class="row w-row">
                    <div class="col-md-1 col-xs-12 w-row1"><span class="span_red">*</span><label for="ruleCode">规则编码</label></div>
                            <div class="col-md-3 col-xs-12 w-row2">
                                <input id="seriNumId" type="hidden" name="serialNumber.ID" value="${serialNumber.ID!}"/>
                                <input id="ruleCode" type="text" name="serialNumber.RULE_CODE" class="form-control form-control-sm" value="${serialNumber.RULE_CODE!}" maxlength="50"/>
                            </div>
                             <div class="col-md-1 col-xs-12 w-row1"><span class="span_red">*</span><label for="ruleName">规则名称</label></div>
                            <div class="col-md-3 col-xs-12 w-row2"><input id="ruleName" type="text" name="serialNumber.RULE_NAME" class="form-control form-control-sm" value="${serialNumber.RULE_NAME!}"
                                maxlength="50"></div>
                             <div class="col-md-1 col-xs-12 w-row1"><span class="span_red">*</span><label for="ruleType">流水号重置规则</label></div>
                            <div class="col-md-3 col-xs-12 w-row2"><epoch:select id="ruleType" list="${lisFun.getDictCode('SYS_SERIAL_NUMBER')}" name="serialNumber.RULE_TYPE" class="form-control form-control-sm"
                                first="false" value="${serialNumber.RULE_TYPE!}"/></div>
                        </div>
                        <div class="row w-row">
                    <div class="col-md-1 col-xs-12 w-row1"><span class="span_red">*</span><label for="seriNumLen">流水号长度</label></div>
                            <div class="col-md-3 col-xs-12 w-row2"><input id="seriNumLen" type="text" name="serialNumber.SERIAL_LENGTH" class="form-control form-control-sm" value="${serialNumber.SERIAL_LENGTH!}"
                                maxlength="9"></div>
                            <div class="col-md-1 col-xs-12 w-row1"><span class="span_red">*</span><label for="curVal">当前值</label></div>
                            <div class="col-md-3 col-xs-12 w-row2"><input id="curVal" type="text" name="serialNumber.CURRENT_VALUE" class="form-control form-control-sm" value="${serialNumber.CURRENT_VALUE!}" maxlength="9"></div>
                             <div class="col-md-1 col-xs-12 w-row1"><span class="span_red">*</span><label for="initVal">初始值</label></div>
                            <div class="col-md-3 col-xs-12 w-row2"><input id="initVal" type="text" name="serialNumber.INIT_VALUE" class="form-control form-control-sm" value="${serialNumber.INIT_VALUE!}" maxlength="9"></div>
                        </div>
                        <div class="row w-row">
                    <div class="col-md-1 col-xs-12 w-row1"><label for="incStep">增加步长</label></div>
                            <div class="col-md-3 col-xs-12 w-row2"><input id="incStep" type="text" name="serialNumber.STEP" class="form-control form-control-sm" value="${serialNumber.STEP!}" maxlength="9"></div>
                             <div class="col-md-1 col-xs-12 w-row1"><label for="prefix">前缀</label></div>
                            <div class="col-md-3 col-xs-12 w-row2"><input id="prefix" type="text" name="serialNumber.PREFIX" class="form-control form-control-sm" value="${serialNumber.PREFIX!}" maxlength="50"></div>
                             <div class="col-md-1 col-xs-12 w-row1"><label for="sepa">分隔符</label></div>
                            <div class="col-md-3 col-xs-12 w-row2"><input id="sepa" type="text" name="serialNumber.SPLIT" class="form-control form-control-sm" value="${serialNumber.SPLIT!}" maxlength="50"></div>
                       </div>
                        @if(!isNew){
                        <div class="row w-row">
                    	<div class="col-md-1 col-xs-12 w-row1"><label for="sysTime">系统时间</label></div>
                            <div class="col-md-3 col-xs-12 w-row2"><input id="sysTime" type="text" class="form-control form-control-sm" value="${serialNumber.SYSTEM_TIME!,'yyyy-MM-dd HH:mm:ss'}" readonly="readonly"></div>
                             <div class="col-md-1 col-xs-12 w-row1"><label for="curTime">数据库时间</label></div>
                            <div class="col-md-3 col-xs-12 w-row2"><input id="curTime" type="text" class="form-control form-control-sm" value="${serialNumber.CUR_TIME!,'yyyy-MM-dd HH:mm:ss'}" readonly="readonly"></div>
                             <div class="col-md-1 col-xs-12 w-row1"></div>
                             <div class="col-md-3 col-xs-12 w-row2"></div>
                        </div>
                        @}
                    
            </form>
        </div>
    </div>
</div>
<script>
$(function(){
    initVld();
    COMMON.inputDigit(["seriNumLen","curVal","initVal","incStep"]);
    _headToolBar.saveBtn(null,null,save);
});
</script>